/*
** StockDB
**
** Copyright (C) 2012 - ? doublegsoft
**
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <time.h>

#include "logging.h"

/*!
** TODO
*/
static void
_log(const char *tag, const char *fmt, va_list ap)
{
  time_t now;
  time(&now);
  char buf[4096];
  vsprintf(buf, fmt, ap);
  char tb[64];
  char *t = ctime(&now);
  strncpy(tb, t, strlen(t) - 1);
  printf("%s [%s]: %s\n", tb, tag, buf);
}

void
stockdb_log_print(const char *fmt, ...)
{
  va_list ap;
  va_start(ap, fmt);
  fprintf(stdout, fmt, ap);
  _log("INFO", fmt, ap);
  va_end(ap);
}

void
stockdb_log_info(const char *fmt, ...)
{
  va_list ap;
  va_start(ap, fmt);
  _log("INFO", fmt, ap);
  va_end(ap);
}

void
stockdb_log_debug(const char *fmt, ...)
{
  va_list ap;
  va_start(ap, fmt);
  _log("DEBUG", fmt, ap);
  va_end(ap);
}

void
stockdb_log_error(const char *fmt, ...)
{
  va_list ap;
  va_start(ap, fmt);
  _log("ERROR", fmt, ap);
  va_end(ap);
}


